<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<script type="text/javascript">
	var myformTemplateId;
	$(function() {
		
		$('#submitForm').form({
			url : '${pageContext.request.contextPath}/apply/submit' ,
			onSubmit : function() {
				if (!$("#checkBoxCC").is(":checked") && $('#comboBoxCC').combobox('getValue') != '${sessionInfo.loginName}' ) {//不是代提交且申请人不是自己
					parent.$.messager.alert('错误', '申请人不是自己', 'error');
					$('#comboBoxCC').combobox('clear');
				}
				if ($("#checkBoxCC").is(":checked") && $('#comboBoxCC').combobox('getValue') == '${sessionInfo.loginName}' ) {//是代提交且申请人是自己
					parent.$.messager.alert('错误', '不能为自己代提交', 'error');
					return false;
				}
				progressLoad();
				myformTemplateId = '${formTemplateId}';
				var isValid = $(this).form('validate');
				if (!isValid) {
					progressClose();
				}
				return isValid;
			},
			success : function(result) {
				progressClose();
				result = $.parseJSON(result);
				if (result.success) {
					parent.$.modalDialog.handler.dialog('close');
					parent.$.messager.alert('结果', result.msg, 'info');
				} else {
					parent.$.messager.alert('错误', result.msg, 'error');
				}
			}
		});
	});
	$('#comboBoxCC').combobox({  
	    url:'${pageContext.request.contextPath}/user/getAllUser',  
	    valueField:'loginName',  
	    textField:'name', 
	    required:true,  
	    onSelect: function(rec){ 
	    	if (!$("#checkBoxCC").is(":checked")) {//不是代提交
				if (rec.loginName != '${sessionInfo.loginName}') {//只能选择自己
					parent.$.messager.alert('错误', '只能选自己', 'error');
					$('#comboBoxCC').combobox('clear');
				}
			}
			
			if ($("#checkBoxCC").is(":checked")) {//是代提交
				$.post('${pageContext.request.contextPath}/user/isInferior', {//判断是否下级
					inforiorLoginName : $('#comboBoxCC').combobox('getValue'),
					loginId:'${sessionInfo.id}'
					}, function(result) {
						if (!result.success) {
							parent.$.messager.alert('错误', result.msg, 'error');
							$('#comboBoxCC').combobox('clear');
						}
					}, 'JSON'
				);
			}
        },
		onLoadSuccess:function(){ 
			if ($("#checkBoxCC").is(":checked")) {
				$('#comboBoxCC').combobox('clear');
			}else{
				$('#comboBoxCC').combobox('select', '${sessionInfo.loginName}');
			}
		}
	}); 
	function isEnglishChar(str) {
		var regEx = /^\d{4}(0[0-9]|1[0-2])([0-2][0-9]|3[0-1])$/;
		var regEx2 = /^\d{4}(0[0-9]|1[0-2])([0-2][0-9]|3[0-1]):\d{4}\d{2}\d{2}$/;
		return str.match(regEx) != null || str.match(regEx2) != null;		 
	}
	$("#checkBoxCC").click( 
		function (){ 
			if ($(this).is(":checked")) {
				$('#comboBoxCC').combobox('reload',"${pageContext.request.contextPath}/user/getInferiors?loginId=${sessionInfo.id}" );  
				//$('#comboBoxCC').combobox('clear');
			} else {
				$('#comboBoxCC').combobox('reload','${pageContext.request.contextPath}/user/getAllUser');  
			}
			//$(this).hide(); 
		}
	);
</script>
<div style="margin: 5px">
	<form id="submitForm" method="post" enctype="multipart/form-data">
		<input type="hidden" name="formTemplateId" value="${formTemplateId} " />
		<input type="hidden" name="loginName" value="${sessionInfo.loginName}" />
		<table cellspacing="0" cellpadding="3" border="1" style="width: 100%">
			<tbody>
				<tr bgcolor="#398EB7">
					<td colspan="2"><font color="#ffffff">流程表单</font></td>
				</tr>
					<c:forEach items="${fields}" var="fieldsVar">
						<tr>
							<td>&nbsp;&nbsp;&nbsp;${fieldsVar.description}:&nbsp;&nbsp;&nbsp;</td>
							<td>
								<c:if test="${fieldsVar.name == 'validateBox'}">
									<input name="${fieldsVar.description}" id="vv000" class="easyui-validatebox" data-options="required:true" />
								</c:if>
								<c:if test="${fieldsVar.name == 'textarea'}">
									<textarea name="${fieldsVar.description}" rows="3" cols="70"></textarea>说明：250个字符内
								</c:if>
								<c:if test="${fieldsVar.name == 'dateBox'}">
									<input name="${fieldsVar.description}" class="easyui-datebox" data-options="required:true" style="width:150px">
									<input name="AMPM" class="easyui-combobox" data-options=" 
								        valueField: 'id',
								        textField: 'text',
								        data: [{
								            id: '上午',
								            text: '上午'
								        },{
								            id: '下午',
								            text: '下午'
								        }]" /> (上午/下午) 
								</c:if>
								<c:if test="${fieldsVar.name == 'datetimeBox'}">
									<input name="${fieldsVar.description}" class="easyui-datetimebox" data-options="required:true" style="width:150px">
								</c:if>
								<c:if test="${fieldsVar.name == 'checkBox'}">
									<input 
									<c:choose>  
									   <c:when test="${fn:contains(sessionInfo.resourceList, '/apply/begin/proxySubmit')}"></c:when>  
									   <c:otherwise>  
									 	  disabled="disabled"  
									   </c:otherwise>  
									</c:choose> 
									id="checkBoxCC" name="${fieldsVar.description}" type="checkbox" style="width:150px">  
								</c:if>
								<c:if test="${fieldsVar.name == 'comboBox'}">
									<input id="comboBoxCC" name="${fieldsVar.description}" style="width:150px">  
								</c:if>
								<c:if test="${fieldsVar.name == 'comboGrid'}">
									<input id="comboGridCC" name="${fieldsVar.description}" value="01" />  
								</c:if>
							</td>
						</tr>
					</c:forEach>
			</tbody>
		</table>
	</form>
</div>